import complex_query from '@dfeidao/atom-nodejs/db/complex-query';
import count from '@dfeidao/atom-nodejs/db/count';
import { IncomingHttpHeaders } from 'http';
import { productid, systemid } from '../../atom/config';
interface Message {
	filter: {
		pn: number
	};
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
		const query = complex_query(action_id, session_id, systemid);
		const dt = await query
	    .add_field('department_staff', 'cabinet_staff_no', 'cabinet_staff_no')
		.add_field('department_staff', 'staff_name', 'staff_name')
		.add_field('department_staff', 'staff_no', 'staff_no')
		.add_field('department_staff', 'sex', 'sex')
		.add_field('department_staff', 'post_name', 'post_name')
		.add_field('department_staff', 'staff_state', 'staff_state')
		.add_field('department_staff', 'deptname', 'deptname')
		.add_field('department_staff', 'createdate', 'createdate')
		.add_field('project_personnel', 'is_resident', 'is_resident')
	    .add_field('project_personnel', 'project_name', 'project_name')
	    .add_field('project_personnel', 'project_no', 'project_no')
		.add_field('project_personnel', 'pub_user_no', 'pub_user_no')
		.inner_join('department_staff','project_personnel',['staff_no','pub_user_no'])
		.page(20, message.filter.pn)
		.exec();

		const { prepare, exec } = count(action_id, session_id, systemid);
        prepare('department_staff', { productid});
        const [c] = await exec();
		return{dt,c};
}
